#region ---Au3Recorder generated code Start ---
Opt("WinWaitDelay",100)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",0)

;Made for Chrome - no bookmarks bar
;125% Screen resolution

$ClickSpeed = 1
$BuffSpeed = 5

$BuffTime = 0.5

$BuffTimeMS = $BuffTime * 60 * 60 * 1000

$SleepTime = 596000
$DelayTime = 5000

$SleptForBuff = 10000000
$SleptForTrade = 0

$MouseMoveSleep = 250
$MouseClickSleep = 10

$TimeoutTime = 1

$FirstBuff = True

; Static Variables for Type selection
$OneOne0 = 796
$OneOne1 = 516;500

$Delta0 = 79
$Delta1 = 38

$FW0 = 1
$FW1 = 1

$HW0 = 1
$HW1 = 1

$HWP0= 2
$HWP1 = 1

$Marble0 = 4
$Marble1 = 2

$Coin0 = 3
$Coin1 = 2

$Horse0 = 2
$Horse1 = 3

$Bow0 = 1
$Bow1 = 3

$Fish0 = 4
$Fish1 = 1

$Water0 = 5
$Water1 = 1

$Bread0 = 4
$Bread1 = 2

$EW0 = 1
$EW1 = 1

$EWP0 = 2
$EWP1 = 1

$Granite0 = 2
$Granite1 = 2

$Xbow0 = 1
$Xbow1 = 3

$BronzeSword0 = 5
$BronzeSword1 = 2

$Cannon0 = 2
$Cannon1 = 3

$Egg0 = 5
$Egg1= 1

$SteelSword0 = 4
$SteelSword1 = 3

$Gold_Ore_0 = 1
$Gold_Ore_1 = 2

$Copper_Ore_0 = 2
$Copper_Ore_1 = 1
;-----------------------------------------------------------------------------------------------

; Button Statics
$AddOffer0 = 293
$AddOffer1 = 869;862

$DeliverSelect0 = 803
$DeliverSelect1 = 675;658

$ReceiveSelect0 = 1142
$ReceiveSelect1 = $DeliverSelect1

$Trade0 = 974
$Trade1 = 607;587

$TradeTab0 = 134
$TradeTab1 = 916;911

$OK0 = 1082
$OK1 = 737;721

$BasicTab0 = 803
$BasicTab1 = 664;649

$IntermediateTab0 = 920
$IntermediateTab1 = $BasicTab1

$AdvancedTab0 = 1028
$AdvancedTab1 = $BasicTab1

$ExpertTab0 = 1139
$ExpertTab1 = $BasicTab1

$InboxClose0 = 1241
$InboxClose1 = 389;374

$TraderClose0 = 1293
$TraderClose1 = 344;329

$GuildClose0 = 1242
$GuildClose1 = 320;305

$DailyBonusClose0 = 970
$DailyBonusClose1 = 703;688;needs reset

$ClickNewQuest0 = 199
$ClickNewQuest1 = 235

$QuestClose0 = 1232
$QuestClose1 = 348

$MoveFromPos0 = 160	;unused
$MoveFromPos1 = 79

$MoveToPos0 = 1559	;unused
$MoveToPos1 = 911

$TipOfTheDayOK0 = 970
$TipOfTheDayOK1 = 730;715

$AcceptTrade0 = 934
$AcceptTrade1 = 743;728

$PlusOne0 = 1019
$PlusOne1 = 746;731

$MinusOne0 = 821
$MinusOne1 = $PlusOne1

$StarMenu0 = 968
$StarMenu1 = 887 ;unused

$BuffMenu0 = 971
$BuffMenu1 = 838 ;unused

$FirstBuff0 = 814
$FirstBuff1 = 644 ;unused

$SecondBuff0 = 868
$SecondBuff1 = 644 ;unused

$BuffFromPos0 = 622
$BuffFromPos1 = 233 ;unused

$BuffToPos0 = 1291
$BuffToPos1 = $BuffFromPos1 ;unused

$CancelBuff0 = 962
$CancelBuff1 = 125 ;unused

$BackToIsland0 = 615
$BackToIsland1 = 1022;1015

$KeepBuffing = True

$PHBuffAdd0 = 1233
$PHBuffAdd1 = 650;633

$PHBuffOK0 = 1107
$PHBuffOK1 = 682;667

;-----------------------------------------------------------------------------------------------
; Exotic Sawmill Buffs
$ExoticSawmillOne0 = 936
$ExoticSawmillOne1 = 447

$ExoticSawmillTwo0 = 820
$ExoticSawmillTwo1 = 519

$ExoticSawmillThree0 = 878
$ExoticSawmillThree1 = 629

$ExoticSawmillFour0 = 1053
$ExoticSawmillFour1 = 663

$ExoticSawmillFive0 = 1171
$ExoticSawmillFive1 = 593

$ExoticSawmillSix0 = 1113
$ExoticSawmillSix1 = 483

$ESBuffOne = True
$ESBuffTwo = True
$ESBuffThree = True
$ESBuffFour = True
$ESBuffFive = True
$ESBuffSix = True

$BuffColor = Dec(0x04cf20, 6)

;-----------------------------------------------------------------------------------------------

; Number Statics
$One0 = 835
$One1 = 745;732 ;725 before

$Two0 = 847
$Two1 = $One1

$Five0 = 848
$Five1 = $One1

$Eight0 = 849
$Eight1 = $One1

$Eleven0 = 850
$Eleven1 = $One1

$Thirteen0 = 851
$Thirteen1 = $One1

$Sixteen0 = 852
$Sixteen1 = $One1

$TwentyFour0 = 855
$TwentyFour1 = $One1

$TwentySeven0 = 856
$TwentySeven1 = $One1

$Thirty0 = 857
$Thirty1 = $One1

$ThirtyEight0 = 860	;True Lock
$ThirtyEight1 = $One1

$FortyOne0 = 861
$FortyOne1 = $One1

$FortyFour0 = 862	;True lock
$FortyFour1 = $One1

$FortySix0 = 863
$FortySix1 = $One1

$FortyNine0 = 864 ;856 before
$FortyNine1 = $One1

$FiftyTwo0 = 865
$FiftyTwo1 = $One1

$SeventyNine0 = 875
$SeventyNine1 = $One1

$Ninety0 = 879
$Ninety1 = $One1

$NinetyNine0 = 882
$NinetyNine1 = $One1

$OneHundredOne0 = 883
$OneHundredOne1 = $One1

$OneHundredTwentyOne0 = 890
$OneHundredTwentyOne1 = $One1

$OneHundredTwentyNine0 = 893
$OneHundredTwentyNine1 = $One1

$OneHundredThirtyFour0 = 895
$OneHundredThrityFour1 = $One1

$OneHundredForty0 = 897
$OneHundredForty1 = $One1

$OneHundredFiftyOne0 = 901
$OneHundredFiftyOne1 = $One1

$OneHundredFiftyNine0 = 904
$OneHundredFiftyNine1 = $One1

$TwoHundredOne0 = 919
$TwoHundredOne1 = $One1

$TwoHundredTwentyFive0 = 928
$TwoHundredTwentyFive1 = $One1

$TwoHundredFifty0 = 937
$TwoHundredFifty1 = $One1

$ThreeHundred0 = 955
$ThreeHundred1 = $One1

$FourHundred0 = 1002
$FourHundred1 = $One1
;------------------------------------------------------------------------------------------------

#cs
Type1	5 coin for 400 HW
Type2	400 HWP for 27coin
Type3	10 coin for 400 HWP
Type4	400 HWP for 400 Horse
Type5	200 HWP for 400 Bows
#ce

Enum $Type1 = 0, $Type2, $Type3, $Type4, $Type5, $Type6, $Type7, $Type8, $Type9, $Type10, $Type11, $Type12, $Type13, $Type14, $Type15, $Type16, $Type17, $Type18, $TypeMax

; ^ is CTRL, ! is ALT

HotKeySet("^{ENTER}", "end")
HotKeySet("^{`}", "SetRandom")
HotKeySet("^{1}", "SetType1")
HotKeySet("^{2}", "SetType2")
HotKeySet("^{3}", "SetType3")
HotKeySet("^{4}", "SetType4")
HotKeySet("^{5}", "SetType5")
HotKeySet("^{6}", "SetType6")

HotKeySet("!{1}", "SetType7")
HotKeySet("!{2}", "SetType8")
HotKeySet("!{3}", "SetType9")
HotKeySet("!{4}", "SetType10")
HotKeySet("!{5}", "SetType11")
HotKeySet("!{6}", "SetType12")
HotKeySet("!{8}", "SetType13")
HotKeySet("!{9}", "SetType14")
HotKeySet("!{0}", "SetType15")



HotKeySet("!{`}", "CreateBuff")

HotKeySet("!{F1}", "TestPosition")

HotKeySet("^{END}", "StopBuffing")
HotKeySet("^{7}", "BuffExoticSawmills")

HotKeySet("^{=}", "Accept")

HotKeySet("!{Z}", "BackToIsland")

;HotKeySet("^{7}", "ColorSearch")
HotKeySet("^{8}", "NightStockup")
HotKeySet("^{9}", "Here")
HotKeySet("^{0}", "NotHere")


HotKeySet("^+{1}", "SetType16")
HotKeySet("^+{2}", "SetType17")
HotKeySet("^+{3}", "SetType18")

;HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d


$random = 1;
$MousePosX = MouseGetPos(0)
$MousePosY = MouseGetPos(1)

$WindowHandle = "TEMP"

$GetRandom = True

$Stockup = False

$DragCounter = 0

$Here = False

Sleep(2000)

Beep()

While True

If $GetRandom Then

$random = Random(0, 100, 1)

If $Stockup == False Then

Select
      Case $random >= 0 AND $random <= 70
          $random = $Type2

      Case $random > 70 AND $random <= 87
          $random = $Type3

	  Case $random > 87 AND $random <= 97
          $random = $Type1

      Case $random > 97 AND $random <= 99
          $random = $Type4

	Case $random > 99 AND $random <= 100
          $random = $Type5

EndSelect

Else

	Select

      Case $random > 0 AND $random <= 70
          $random = $Type5

	  Case $random > 70 AND $random <= 80
		  $random = $Type16

	  Case $random > 80 AND $random <= 90
          $random = $Type3

	  Case $random > 90 AND $random <= 95
          $random = $Type1

	  Case $random > 95 AND $random <= 100
          $random = $Type6

	EndSelect

EndIf


EndIf

$WindowHandle = WinGetHandle("[ACTIVE]")

If Not WinActive("The Settlers Online - Zeus [Realm 1] - Google Chrome","") Then WinActivate("The Settlers Online - Zeus [Realm 1] - Google Chrome","")
;WinWaitActive("The Settlers Online - Zeus [Realm 1] - Google Chrome","")

$DragCounter = 0;

#CS
Do
MouseMove($MoveFromPos0, $MoveFromPos1, $ClickSpeed)
MouseDown("left")
MouseMove($MoveToPos0, $MoveToPos1, $ClickSpeed)
MouseUp("left")
$DragCounter+=1
Until $DragCounter == 3

MouseWheel("up", 5)
#CE

BackToIsland()

Sleep(3000)

;Send("3")
;Send("3")
;Send("3")

; Close Open Windows
MouseClick("left",$ClickNewQuest0, $ClickNewQuest1, $ClickSpeed)
MouseClick("left",$QuestClose0, $QuestClose1, $ClickSpeed)

MouseClick("left",$DailyBonusClose0, $DailyBonusClose1, $ClickSpeed)
MouseClick("left",$InboxClose0, $InboxClose1, $ClickSpeed)
MouseClick("left",$TraderClose0, $TraderClose1, $ClickSpeed)
MouseClick("left",$GuildClose0, $GuildClose1, $ClickSpeed)

; Trade Tab
MouseClick("left",$TradeTab0,$TradeTab1,$ClickSpeed)

; Add Offer
MouseClick("left",$AddOffer0,$AddOffer1,$ClickSpeed)

; Deliver Select
MouseClick("left",$DeliverSelect0,$DeliverSelect1,$ClickSpeed)

;Send("3")

;Case Statement
Select

Case $random == $Type1
	;------------------ Type 1  3 coin for 400 HW -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $Two0, $Two1, $ClickSpeed)

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type2
	;------------------ Type 2 400 HWP for 24 coin -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($HWP0-1)*$Delta0), $OneOne1+(($HWP1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type3

	;------------------ Type 3 1 coin for 400 fir logs -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	;MouseClick("left", $OneHundredFiftyOne0, $OneHundredFiftyOne1, $ClickSpeed)

	;MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

	MouseClick("left", $One0, $One1, $ClickSpeed)

	;MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

	;-------------------------------------------------------------------

Case $random == $Type4
	;------------------ Type 3 80 EWP for 45 coin -----------------------
	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($EWP0-1)*$Delta0), $OneOne1+(($EWP1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $SeventyNine0, $SeventyNine1, $ClickSpeed)
	;-------------------------------------------------------------------

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

Case $random == $Type5
	;------------------ Type 3 5 coin for 400 Bread -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $Five0, $Five1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type6
	;------------------ Type 6 400 Water for 400 Fish -----------------------
	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Water0-1)*$Delta0), $OneOne1+(($Water1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type7
	;------------------ Type 7 27 coin for 50 Granite -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwentySeven0, $TwentySeven1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type8
	;----------------- Type8 200 HWP for 200 Marble -------------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($HWP0-1)*$Delta0), $OneOne1+(($HWP1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)


	;-------------------------------------------------------------------------

Case $random == $Type9
	;------------------ Type 9 400 Bread for 400 Bronze Swords
	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Bread0-1)*$Delta0), $OneOne1+(($Bread1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;---------------------------------------------------------------------

Case $random == $Type10
	;------------------ Type 10 400 Marble for 26 coin --------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Marble0-1)*$Delta0), $OneOne1+(($Marble1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)


Case $random == $Type11
	;------------------ Type 11 400 coin for 200 xbow -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $NinetyNine0, $NinetyNine1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type12
	;------------------ Type 12 400 Fish for 5 Gold -----------------------

	MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Fish0-1)*$Delta0), $OneOne1+(($Fish1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

Case $random == $Type13
	;------------------ Type 13 400 Bronze Swords for 70 Steel Swords -----------------------

	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($BronzeSword0-1)*$Delta0), $OneOne1+(($BronzeSword1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

Case $random == $Type14
	;------------------ Type 14 80 Steel Swords for 49 Gold -----------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($SteelSword0-1)*$Delta0), $OneOne1+(($SteelSword1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $SeventyNine0, $SeventyNine1, $ClickSpeed)

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

Case $random == $Type15

	;------------------ Type 15 XX Gold for 100 Gold Ore-----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $Eight0, $Eight1, $ClickSpeed)

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

Case $random == $Type16
	;------------------ Type 16 1 Gold for 134 Copper Ore -----------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $One0, $One1, $ClickSpeed)

Case $random == $Type17

	;----------------- Type 17 160 Granite for 140 Gold --------------------
	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Granite0-1)*$Delta0), $OneOne1+(($Granite1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $OneHundredFiftyNine0, $OneHundredFiftyNine1, $ClickSpeed)
	;-------------------------------------------------------------------

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

Case $random == $Type18

	;---------------- Type 18 200 EWP for 200 Granite-----------------------------

	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($EWP0-1)*$Delta0), $OneOne1+(($EWP1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)




EndSelect

; Select OK Button
MouseClick("left", $OK0, $OK1, $ClickSpeed)

$ThisHWND = WinGetHandle("[ACTIVE]")

; Receive Select
MouseClick("left", $ReceiveSelect0, $ReceiveSelect1, $ClickSpeed)

;Case Statement
Select

Case $random == $Type1
	;------------------ Type 1  5coin for 400 HW -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($HW0-1)*$Delta0), $OneOne1+(($HW1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type2
	;------------------ Type 2 400 HWP for 27coin  -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwentyFour0, $TwentyFour1, $ClickSpeed)
	;-------------------------------------------------------------------

	;MouseClick("left", $Thirteen0, $Thirteen1, $ClickSpeed)

Case $random == $Type3

	;---------------- Type 3 1 coin for 400 fir logs -------------------
	MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($FW0-1)*$Delta0), $OneOne1+(($FW1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

Case $random == $Type4
	;------------------ Type 4 80 EWP for 45 Coin -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FortyFour0, $FortyFour1, $ClickSpeed)

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)
	;--------------------------------------------------------------------

Case $random == $Type5

	#cs
	;------------------ Type 5 200 HWP for 400 Bows -----------------------
	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Bow0-1)*$Delta0), $OneOne1+(($Bow1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

	#ce

	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Bread0-1)*$Delta0), $OneOne1+(($Bread1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

Case $random == $Type6
	;------------------ Type 5 200 HWP for 400 Bows -----------------------
	MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Fish0-1)*$Delta0), $OneOne1+(($Fish1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

Case $random == $Type7

	;----------------- Type 7 27 coin for 49 Granite --------------------
	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Granite0-1)*$Delta0), $OneOne1+(($Granite1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FortyNine0, $FortyNine1, $ClickSpeed)
	;-------------------------------------------------------------------

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

Case $random == $Type8

#cs
	;----------------- Type 8 400 coin for 200 xbow --------------------
	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Xbow0-1)*$Delta0), $OneOne1+(($Xbow1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)
	;-------------------------------------------------------------------

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

	#Ce

	;----------------- Type 8 200 hwp for 200 marble
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Marble0-1)*$Delta0), $OneOne1+(($Marble1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

Case $random == $Type9

	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($BronzeSword0-1)*$Delta0), $OneOne1+(($BronzeSword1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)

Case $random == $Type10

#cs
	;------------------ Type 10 50 cannon for 350 coin -----------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FourHundred0, $FourHundred1, $ClickSpeed)
	;-------------------------------------------------------------------

	#ce

	;------------------ Type 10 400 marble for 26 coin --------------------------
	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwentySeven0, $TwentySeven1, $ClickSpeed)


Case $random == $Type11

	;------------------ Type 5 150 coin for 40 eggs -----------------------
	MouseClick("left", $BasicTab0, $BasicTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Egg0-1)*$Delta0), $OneOne1+(($Egg1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FortyOne0, $FortyOne1, $ClickSpeed)
	;-------------------------------------------------------------------
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

Case $random == $Type12

	;---------------- Type 12 400 Fish for 5 Gold -------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $Five0, $Five1, $ClickSpeed)

Case $random == $Type13
	;------------------ Type 12 400 Bronze Swords for 70 Steel Swords -----------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($SteelSword0-1)*$Delta0), $OneOne1+(($SteelSword1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $SeventyNine0, $SeventyNine1, $ClickSpeed)

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)
	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)

Case $random == $Type14

	;---------------- Type 14 80 Steel Swords for 49 Gold -------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $FortyNine0, $FortyNine1, $ClickSpeed)

Case $random == $Type15

	;---------------- Type 15 XX Gold for 100 Gold Ore -------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Gold_Ore_0-1)*$Delta0), $OneOne1+(($Gold_Ore_1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $NinetyNine0, $NinetyNine1, $ClickSpeed)

	MouseClick("left", $PlusOne0, $PlusOne1, $ClickSpeed)

Case $random == $Type16
	;------------------ Type 13 1 Gold for 134 Copper Ore -----------------------

	MouseClick("left", $IntermediateTab0, $IntermediateTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Copper_Ore_0-1)*$Delta0), $OneOne1+(($Copper_Ore_1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $OneHundredThirtyFour0, $OneHundredThrityFour1 , $ClickSpeed)

Case $random == $Type17
	;------------------ Type 17 160 Granite for 140 Gold -----------------------

	MouseClick("left", $AdvancedTab0, $AdvancedTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Coin0-1)*$Delta0), $OneOne1+(($Coin1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $OneHundredForty0, $OneHundredForty1, $ClickSpeed)

Case $random == $Type18

	;----------------- Type 18 200 EWP for 200 Granite --------------------
	MouseClick("left", $ExpertTab0, $ExpertTab1, $ClickSpeed)

	MouseClick("left", $OneOne0+(($Granite0-1)*$Delta0), $OneOne1+(($Granite1-1)*$Delta1), $ClickSpeed)

	MouseClick("left", $TwoHundredOne0, $TwoHundredOne1, $ClickSpeed)
	;-------------------------------------------------------------------

	MouseClick("left", $MinusOne0, $MinusOne1, $ClickSpeed)



EndSelect

; Select OK Button
MouseClick("left", $OK0, $OK1, $ClickSpeed)


; Send Trade
MouseClick("left", $Trade0, $Trade1, $ClickSpeed)

Sleep(50)

MouseClick("left", $Trade0, $Trade1, $ClickSpeed)

;Send("3")


;------------------------- Return to last window ----------------------------------------------

If $Here Then
MouseMove($MousePosX, $MousePosY, $ClickSpeed)

; Activate last known Window and move mouse back to where it was
WinActivate($WindowHandle)
;WinWaitActive($WindowHandle,"")
EndIf

#cs

$SleptForTrade = 0
$SleptForBuff += 12000

Do

	If $SleptForBuff>=$BuffTimeMS Then
		BuffExoticSawmills()
		$SleptForTrade
	EndIf

	Sleep(1000)

	$SleptForTrade += 1000
	$SleptForBuff += 1000

Until $SleptForTrade>=$SleepTime

#ce


;BuffExoticSawmills()

Sleep($SleepTime - $DelayTime)

Beep()

Sleep($DelayTime)

Beep(800)

WEnd

; Functions -----------------------------------------------------------------------------

Func SetType1()
	$GetRandom = False
	$random = $Type1

	MsgBox(0, "SetType1", "3 coin for 400 Hardwood", $TimeoutTime)
EndFunc

Func SetType2()
	$GetRandom = False
	$random = $Type2

	MsgBox(0, "SetType2", "400 Hardwood Planks for 24 coin", $TimeoutTime)
EndFunc

Func SetType3()
	$GetRandom = False
	$random = $Type3

	;MsgBox(0, "SetType3", "11 coin for 400 Hardwood Planks", $TimeoutTime)
	MsgBox(0, "SetType3", "1 coin for 400 fir logs", $TimeoutTime)
EndFunc

Func SetType4()
	$GetRandom = False
	$random = $Type4

	;MsgBox(0, "SetType4", "400 Hardwood Planks for 400 Horses", $TimeoutTime)
	MsgBox(0, "SetType4", "400 Exotic Wood Planks for 225 coin", $TimeoutTime)
EndFunc

Func SetType5()
	$GetRandom = False
	$random = $Type5

	;MsgBox(0, "SetType5", "200 Hardwood Planks for 400 Bows", $TimeoutTime)
	MsgBox(0, "SetType5", "5 coin for 400 bread", $TimeoutTime)
EndFunc

Func SetType6()
	$GetRandom = False
	$random = $Type6

	MsgBox(0, "SetType6", "400 Water for 400 Fish", $TimeoutTime)
EndFunc

Func SetType7()
	$GetRandom = False
	$random = $Type7

	MsgBox(0, "SetType7", "27 coin for 50 Granite", $TimeoutTime)
EndFunc

Func SetType8()
	$GetRandom = False
	$random = $Type8

	MsgBox(0, "SetType8", "200 HWP for 200 Marble", $TimeoutTime)
EndFunc

Func SetType9()
	$GetRandom = False
	$random = $Type9

	MsgBox(0, "SetType9", "400 Bread for 400 Bronze Sword", $TimeoutTime)
EndFunc

Func SetType10()
	$GetRandom = False
	$random = $Type10

	MsgBox(0, "SetType10", "400 Marble for 27 Coin", $TimeoutTime)
EndFunc

Func SetType11()
	$GetRandom = False
	$random = $Type11

	MsgBox(0, "SetType1", "150 coin for 40 eggs", $TimeoutTime)
EndFunc

Func SetType12()
	$GetRandom = False
	$random = $Type12

	MsgBox(0, "SetType1", "400 Fish for 5 Coins", $TimeoutTime)
EndFunc

Func SetType13()
	$GetRandom = False
	$random = $Type13

	MsgBox(0, "SetType1", "400 Bronze Swords for 70 Steel Swords", $TimeoutTime)
EndFunc

Func SetType14()
	$GetRandom = False
	$random = $Type14

	MsgBox(0, "SetType1", "80 Steel Swords for 49 Gold", $TimeoutTime)
EndFunc

Func SetType15()
	$GetRandom = False
	$random = $Type15

	MsgBox(0, "SetType1", "XX Gold for 100 Gold Ore", $TimeoutTime)
EndFunc

Func SetType16()
	$GetRandom = False
	$random = $Type16

	MsgBox(0, "SetType1", "1 Gold for 160 Copper Ore", $TimeoutTime)
EndFunc

Func SetType17()
	$GetRandom = False
	$random = $Type17

	MsgBox(0, "SetType1", "160 Granite for 140 Gold", $TimeoutTime)
EndFunc

Func SetType18()
	$GetRandom = False
	$random = $Type18

	MsgBox(0, "SetType1", "200 EWP for 200 Granite", $TimeoutTime)
EndFunc


Func SetRandom()
	$GetRandom = True

	MsgBox(0, "SetRandom", "Random", $TimeoutTime)
EndFunc

Func NightStockup()
	If $Stockup == False Then
		MsgBox(0, "SetNightTimeStockup", "On", $TimeoutTime)
		$Stockup = True
	Else
		MsgBox(0, "SetNightTimeStockup", "Off", $TimeoutTime)
		$Stockup = False
EndIf

EndFunc

Func Here()
	$Here = True
	MsgBox(0, "Here", "HERE!", $TimeoutTime)
EndFunc

Func NotHere()
	$Here = False
	MsgBox(0, "Not Here", "BE GONE!", $TimeoutTime)
EndFunc

Func Accept()
	$TempMousePos0 = MouseGetPos(0)
	$TempMousePos1 = MouseGetPos(1)

	MouseClick("left", $TempMousePos0, $TempMousePos1, $ClickSpeed)

	MouseClick("left", $AcceptTrade0, $AcceptTrade1, $ClickSpeed)

	MouseMove($TempMousePos0, $TempMousePos1, $ClickSpeed)
EndFunc

Func BackToIsland()

	MouseClick("left", $BackToIsland0, $BackToIsland1, $ClickSpeed)
	MouseMove($BackToIsland0, 839, $ClickSpeed)

EndFunc

Func TestPosition()

;MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)

;CheckExoticSawmills()

;MouseClick("left", $Forty0, $Forty1, $ClickSpeed)

BackToIsland()

EndFunc

Func CreateBuff()

	$MousePosX = MouseGetPos(0)
	$MousePosY = MouseGetPos(1)

	MouseClick("left")

	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)
	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)
	MouseClick("left", $PHBuffAdd0, $PHBuffAdd1, $ClickSpeed)

	MouseClick("left", $PHBuffOK0, $PHBuffOK1, $ClickSpeed)

	MouseMove($MousePosX, $MousePosY, $ClickSpeed)

EndFunc

Func CheckExoticSawmills()

	AutoItSetOption("PixelCoordMode", 0)

	Send("3")
	;Send("3")
	;Send("3")

	MouseWheel("up", 10)

	MouseMove($BuffFromPos0, $BuffFromPos1, $BuffSpeed)
	MouseDown("left")
	MouseMove($BuffToPos0, $BuffToPos1, $BuffSpeed)
	MouseUp("left")

#cs

	MouseClick("left", $ExoticSawmillOne0, $ExoticSawmillOne1, $ClickSpeed)

	Sleep(250)

	Local $var = PixelGetColor(1779, 746)

	If $var == $BuffColor Then
		$ESBuffOne = False
	Else
		$ESBuffOne = True
	EndIf

#ce


#cs
	Local $coord = PixelSearch(1769, 722, 1802, 752, 0x04cf20, 15, $ThisHWND)
If Not @error Then
    MsgBox(0, "X and Y are:", $coord[0] & "," & $coord[1], 500, $ThisHWND)
EndIf

#ce

	;MsgBox(0, "The hex color is", Hex($var, 6),2)

EndFunc

Func BuffExoticSawmills()

	$KeepBuffing = true

	Send("3")
	;Send("3")
	;Send("3")

	MouseWheel("up", 10)

	MouseMove($BuffFromPos0, $BuffFromPos1, $BuffSpeed)
	MouseDown("left")
	MouseMove($BuffToPos0, $BuffToPos1, $BuffSpeed)
	MouseUp("left")

	;---------------- Level 1 ------------------------------------
	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillOne0, $ExoticSawmillOne1, $BuffSpeed)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillTwo0, $ExoticSawmillTwo1, $BuffSpeed)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	;---------------- Level 2 ------------------------------------
	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillThree0, $ExoticSawmillThree1, $BuffSpeed+5)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillFour0, $ExoticSawmillFour1, $BuffSpeed)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillFive0, $ExoticSawmillFive1, $BuffSpeed)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	If $KeepBuffing == True Then
	FirstBuff()
	MouseMove($ExoticSawmillSix0, $ExoticSawmillSix1, $BuffSpeed)
	Sleep($MouseMoveSleep)
	MouseDown("left")
	Sleep($MouseClickSleep)
	MouseUp("left")
	CancelBuff()
	EndIf

	$SleptForBuff = 0

EndFunc

Func FirstBuff()

	MouseClick("left", $StarMenu0, $StarMenu1, $ClickSpeed)
	MouseClick("left", $BuffMenu0, $BuffMenu1, $ClickSpeed)

	If $FirstBuff == True Then
	MouseClick("left", $FirstBuff0, $FirstBuff1, $ClickSpeed)
	$FirstBuff = False
	Else
	MouseClick("left", $SecondBuff0, $SecondBuff1, $ClickSpeed)
	$FirstBuff = True
	EndIf

EndFunc

Func CancelBuff()

	MouseClick("left", $CancelBuff0, $CancelBuff1, $ClickSpeed)

EndFunc

Func StopBuffing()

	$KeepBuffing = False

EndFunc

;-----------------------------------------------------------------------------------------------------

Func end()
   Exit
EndFunc

Func _WinWaitActivate($title,$text,$timeout=0)
	WinWait($title,$text,$timeout)
	If Not WinActive($title,$text) Then WinActivate($title,$text)
	WinWaitActive($title,$text,$timeout)
EndFunc

;End --------------------------------------------------------------------------------------------------
